home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip1292.zip / C_LINES.AWK < prev    next >
Text File  |  1992-12-26  |  1KB  |  44 lines

  1. # count lines in a C program, not counting comments, blank lines or 
  2. # form feeds
  3. # does separate count of preprocessor directives
  4. # if a preprocessor directive is commented out, it does not count
  5. #
  6. # By: Dan Kozak
  7.  
  8. {
  9.  if (file == "") {
  10.   file = FILENAME
  11.  }
  12.  if (file != FILENAME) {
  13.   printf("Number of lines in %s is: %d\n",file,nl+ppd)
  14.   printf("Number of preprocessor directives is: %d\n",ppd)
  15.   printf("Number of lines excluding preprocessor directives is: %d\n\n",nl)
  16.   file = FILENAME
  17.   tnl += nl
  18.   tppd += ppd
  19.   nl = 0
  20.   ppd = 0
  21.  }
  22.  
  23.  if ($0 == "") { ; }
  24.  else if ($1 ~ /^\/\*/ && $NF ~ /\*\/$/) { ; }
  25.  else if ($0 ~ /\/\*/ && $0 !~ /\*\//) { in_comment = 1 }
  26.  else if ($0 !~ /\/\*/ && $0 ~ /\*\//) { in_comment = 0 }
  27.  else if (in_comment) { ; }
  28.  else if ($1 ~ /^#/) { ppd++ }
  29.  else { nl++ }
  30. }
  31.  
  32. END { printf("Number of lines in %s is: %d\n",file,nl+ppd)
  33.       printf("Number of preprocessor directives is: %d\n",ppd)
  34.       printf("Number of lines excluding preprocessor directives is: 
  35. %d\n\n",nl)
  36.       file = FILENAME
  37.       tnl += nl
  38.       tppd += ppd
  39.       printf("Total number of lines is: %d\n",tnl+tppd)
  40.       printf("Number of preprocessor directives is: %d\n",tppd)
  41.       printf("Number of lines excluding preprocessor directives is: 
  42. %d\n",tnl)
  43.     }
  44.